<?php
class HTTPRequest {
	protected $adapter;
	protected $_listens = array();

	public function __get($name){
		if(isset($this->adapter->$name))
			return $this->adapter->$name;
	}
	public function __set($name,$value){
		switch($name){
			case 'verb':
				$this->adapter->verb = strtoupper($value);
				break;
			case 'uri':
			case 'url':
				$this->adapter->uri = new HTTPRequestUri($value);
				break;
			case 'content':
				if(in_array($value)){
					$this->adapter->body = http_build_query($value);
					$this->setHeader('Content-Type','application/x-www-form-urlencode');
					if($this->adapter->verb == 'GET')
						$this->adapter->verb = 'POST';
				}else{
					$this->adapter->body = $value;
				}
				break;
			case 'requestTimeout':
				$this->adapter->$name = (int)$value;
				break;
			default:
				$this->adapter->$name = $value;
				break;
		}
	}

	public function __construct($url=''){
		if(extension_loaded('curl'))
			$this->adapter = new HTTPRequestAdapterCurl;
		else 
			throw new Exception('未加载CURL扩展,请与管理员联系 spricity@gmail.com');
		//$this->adapter->setListeners($this->_listeners);
		if($url)
			$this->url = $url;
		else
			$this->url = SC::app()->webThumbApi;

	}
	public function sendRequest(){
		return $this->adapter->sendRequest();
	}
}